#include "TGeoManager.h"
#include "TGeoMatrix.h"
#include "../macro/ReadMap.c"
#include <sstream>
#include <string>

void DrawSquare(double,double,double,int,TGeoManager*,TGeoVolume*,TGeoMedium*,int copyNum);

void MappingRoot(char* filePath)
{
	if(gGeoManager) gGeoManager->Delete();
	TGeoManager* geom = new TGeoManager("geom","geometry manager");

	TGeoMaterial* vacuum=new TGeoMaterial("vacuum",0,0,0);
	TGeoMedium* air = new TGeoMedium("air",0,vacuum);

	TGeoVolume* world = geom->MakeBox("world",air,100,100,10);
	geom->SetTopVolume(world);
	geom->SetTopVisible(false);

	int numberOfCrystals = 0;
	double** crystalInfo = ReadMap(filePath,numberOfCrystals);

	for(int i=0 ;i<numberOfCrystals ;i++)
	{
		DrawSquare(crystalInfo[i][0],crystalInfo[i][1],crystalInfo[i][2],crystalInfo[i][3],geom,world,air,i);
	}

	geom->CloseGeometry();
	world->Draw();
}

void DrawSquare(double x,double y,double size,int color,TGeoManager* geom,TGeoVolume* world,TGeoMedium* air,int copyNum)
{
	TGeoVolume* square = geom->MakeBox("square",air,size/2,size/2,0);
	square->SetLineColor(color);
	square->SetFillColor(color);
	TGeoTranslation* translation = new TGeoTranslation("square",x,y,0);
	world->AddNode(square,copyNum,translation);
}
